<template>
  <div class="songs-container">
    <div class="tab-bar">
      <span class="item" @click="tag=0" :class="{active:tag==0}">全部</span>
      <span class="item" @click="tag=7" :class="{active:tag==7}">华语</span>
      <span class="item" @click="tag=96" :class="{active:tag==96}">欧美</span>
      <span class="item" @click="tag=8" :class="{active:tag==8}">日本</span>
      <span class="item" @click="tag=16" :class="{active:tag==16}">韩国</span>
    </div>
    <!-- 底部的table -->
    <table class="el-table playlit-table">
      <thead>
        <th></th>
        <th></th>
        <th>音乐标题</th>
        <th>歌手</th>
        <th>专辑</th>
        <th>时长</th>
      </thead>
      <tbody>
        <tr class="el-table__row" v-for="(item,i) in lists" :key="i" @click="playMusic(item.id)">
          <td>{{i+1}}</td>
          <td>
            <div class="img-wrap">
              <img :src="item.album.picUrl" alt="" />
              <span class="iconfont icon-play"></span>
            </div>
          </td>
          <td>
            <div class="song-wrap">
              <div class="name-wrap">
                <span>{{item.name}}</span>
                <span class="iconfont icon-mv"></span>
              </div>
              <span></span>
            </div>
          </td>
          <td>{{item.artists[0].name}}</td>
          <td>{{item.album.name}}</td>
          <td>{{item.duration | dateFormat}}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
  import { getTopSongAPI, getSongUrlAPI } from '@/api'
  export default {
    name: 'songs',
    data() {
      return {
        lists: [],
        tag: 0
      };
    },
    watch: {
      tag() {
        this.getLists()
      }
    },
    created() {
      this.getLists()
    },
    methods: {
      async getLists() {
        const topSongRes = await getTopSongAPI({ type: this.tag })
        this.lists = topSongRes.data.data
      },
      async playMusic(id) {
        const songUrlRes = await getSongUrlAPI(id)
        this.$parent.audio.url = songUrlRes.data.data[0].url
        this.$emit('newsInfo', id);
      }
    },
  };
</script>

<style>

</style>